#include "System.h"

// Calculate the CRC for a packet using
// the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1)



WORD CalcCRC(BYTE *data, WORD length)
{
WORD i,crc;
	crc = 0xffff;
	for (i=0;i<length;i++)
	{
		crc = (crc >> 8) | (crc << 8); 
		crc ^= (WORD) data[i];
		crc ^= (crc & 0xff) >> 4;
		crc ^= (crc << 8) << 4;
		crc ^= ((crc & 0xff) << 4) << 1;
	}
	return crc;
}



